package com.pubinfo.passbook.common.model.http.baseEntity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import lombok.Data;
import lombok.SneakyThrows;

import java.io.Serializable;

@Data
public class Message implements Serializable {
  private static final long serialVersionUID = 3476490027690554650L;
  
  private String message;
  
  @JacksonXmlProperty(localName = "bizMessage")
  @JacksonXmlCData(value = true)
  public String getMessage() {
    return message;
  }
  
  public Message() {
  }
  
  @SneakyThrows
  public Message(Object bizMessage) {
    XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    this.message = xmlMapper.writeValueAsString(bizMessage);
  }
  
  public void setBizMessage(Object bizMessage) throws JsonProcessingException {
    XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    this.message = xmlMapper.writeValueAsString(bizMessage);
  }
  
}
